<?php

function show_receive_date($date)
{
	if ($date != null) {
		echo time_to_str($date);
	}
	else {
		echo icon_tag('exclamation').' (non reçu)';
	}
}

// détails d'un membre
$member = member_get_by_id($_GET['id']);

if ($member != NULL) {
	?>

	<div id="member-tabs-container">
		<ul style="font-size: 11px;">
			<li><a href="#member-tab-civilite">Civilité</a></li>
			<?php if ($member['status_code'] != 'ADMIN' && $member['status_code'] != 'MODERATOR') { ?>
				<li><a href="#member-tab-inscription">Inscription</a></li>
			<?php } ?>
			<li><a href="#member-tab-history">Historique des statuts</a></li>
			<li><a href="#member-tab-connections">Connexions</a></li>
		</ul>

		<div id="member-tab-civilite">
			<table class="details">
				<tr>
					<td>Nom</td>
					<td><?php echo $member['name'] ?></td>
				</tr>
				<tr>
					<td>Prénom</td>
					<td><?php echo $member['firstname'] ?></td>
				</tr>
				<tr>
					<td>Statut</td>
					<td><strong style="color: <?php echo $member['status_color'] ?>"><?php echo $member['status_label'] ?></strong></td>
				</tr>
				<tr>
					<td>Date de naissance</td>
					<td><?php echo $member['birth'].'&nbsp;('.get_age($member['birth']).' ans)' ?></td>
				</tr>
				<tr>
					<td>Sexe</td>
					<td><?php echo $member['gender'].' '; echo icon_tag($member['gender'] == 'M' ? 'male' : ($member['gender'] == 'F' ? 'female' : 'help')) ?></td>
				</tr>
				<tr>
					<td>Adresse</td>
					<td><?php echo $member['address'].'<br />'.$member['postal_code'].' '.$member['city'] ?></td>
				</tr>
				<tr>
					<td>E-mail</td>
					<td><?php link_mail_to($member['email']) ?></td>
				</tr>
				<tr>
					<td>Téléphone fixe</td>
					<td><?php echo $member['homephone'] != '' ? $member['homephone'] : '(non indiqué)' ?></td>
				</tr>
				<tr>
					<td>Téléphone portable</td>
					<td><?php echo $member['cellphone'] != '' ? $member['cellphone'] : '(non indiqué)' ?></td>
				</tr>
			</table>
			<?php
			if ($member['idParent'] != 0) {
				$parent = member_get_parent($member['idParent']);
				if ($parent != NULL) {
				?>
					<h3>Parent responsable du mineur</h3>
					<table class="details">
						<tr>
							<td>Nom</td>
							<td><?php echo $parent['name'] ?></td>
						</tr>
						<tr>
							<td>Prénom</td>
							<td><?php echo $parent['firstname'] ?></td>
						</tr>
						<tr>
							<td>Numéro d'urgence</td>
							<td><?php echo $parent['emergency_phone'] ?></td>
						</tr>
						<tr>
							<td>E-mail</td>
							<td><?php link_mail_to($parent['email']) ?></td>
						</tr>
					</table>
					<?php
				}
			}
			?>
		</div>
		<?php if ($member['status_code'] != 'ADMIN' && $member['status_code'] != 'MODERATOR') { ?>
		<div id="member-tab-inscription">
			<table class="details">
				<tr>
					<td>Date de demande</td>
					<td><?php echo time_to_str($member['date_pre_registration']) ?></td>
				</tr>
				<tr>
					<td>Date de validation</td>
					<td><?php echo $member['date_registration'] != 0 ? time_to_str($member['date_registration']) : '(inscription non validée)' ?></td>
				</tr>
				<tr>
					<td>Gymnase</td>
					<td><?php echo $member['gym_name'] ?></td>
				</tr>
				<tr>
					<td>Créneau demandé</td>
					<td><?php echo $member['cat_name'] ?></td>
				</tr>
				<tr>
					<td>Date réception chèque inscription</td>
					<td><?php show_receive_date($member['date_registration_check']) ?></td>
				</tr>
				<tr>
					<td>Date réception certificat médical</td>
					<td><?php show_receive_date($member['date_medical_certificate']) ?></td>
				</tr>
				<tr>
					<td>Niveau d'escalade</td>
					<td><?php echo $member['climbing_level'] ?></td>
				<tr>
				</tr>
					<td>Nombre d'années de pratique</td>
					<td><?php echo $member['climbing_years_practice'] ?></td>
				<tr>
				</tr>
					<td>Souhaite participer à des compétitions</td>
					<td><?php echo icon_tag($member['competitions'] ? 'tick' : 'cross') ?></td>
				<tr>
				</tr>
					<td>Bénéficiaire du pass92</td>
					<td><?php echo icon_tag($member['has_pass92'] ? 'tick' : 'cross') ?></td>
				<tr>
				</tr>
					<td>Désire un justificatif d'inscription</td>
					<td><?php echo icon_tag($member['need_registration_proof'] ? 'tick' : 'cross') ?></td>
				<tr>
				</tr>
					<td>Droit d'utiliser les images du membre ou de ses enfants</td>
					<td><?php echo icon_tag($member['authorize_image_use'] ? 'tick' : 'cross') ?></td>
				</tr>
			</table>
		</div>
		<?php } ?>
		<div id="member-tab-history">
			<table class="details">
				<tr>
					<th>Statut</th>
					<th>Effectué le</th>
					<th>Effectué par</th>
				</tr>
				<?php
				$history = member_get_history($member['id']);
				while ($row = mysql_fetch_assoc($history)) {
					// on affiche le créateur sauf si statut affecté par l'user lui-même
					$creator = $row['creator_id'] == $row['user_id'] ? '-' : ($row['creator_firstname'].' '.$row['creator_name']);
					echo '
					<tr>
						<td style="color: '.$row['status_color'].'">'.$row['status_label'].'</td>
						<td>'.time_to_str($row['created_at']).'</td>
						<td>'.$creator.'</td>
					</tr>';
				}
				?>

			</table>
		</div>
		<div id="member-tab-connections">
			<table class="details">
				<tr>
					<td>Nombre de connexions au site</td>
					<td><?php echo $member['connection_count'] ?></td>
				<tr>
				</tr>
					<td>Date de dernière connexion</td>
					<td><?php echo $member['last_connection'] != '' ? date_to_str($member['last_connection']) : '(jamais)' ?></td>
				<tr>
			</table>
		</div>
	</div>
	<?php
}
else {
	?>
	<p class="error">Le membre demandé n'existe pas</p>
	<?php
}
?>
